<script setup lang="ts">
import mtHtml from '../components/mp-html/components/mp-html/mp-html.vue'

import { getServiceProtocol } from '@/api/app'
import { useAppStore } from '@/stores/app'
import { useLogin } from '@/stores/login'

const appStore = useAppStore()
const useLogiStore = useLogin()

const content = ref<string>('')

const language = ref('zh-cn')
//   类型：1.用户协议 2.隐私政策 3.服务协议 4.退换货政策 5.退款政策 6.帮助中心(FAQ)

const typeList = [
    {},
    {
        name: '用户协议',
        value: 1
    },
    {
        name: '隐私政策',
        value: 2
    },
    {
        name: '服务协议',
        value: 3
    },
    {
        name: '退换货政策',
        value: 4
    },
    {
        name: '退款政策',
        value: 5
    },
    {
        name: '帮助中心(FAQ)',
        value: 6
    }
]

onLoad(async (options: any) => {
    console.log(typeList[options.type || 1] as string)
    // 隐藏登录框
    useLogiStore.showLogin && (useLogiStore.showLogin = false)

    // 设置nav title
    if (options.title) {
        uni.setNavigationBarTitle({
            title: decodeURI(options.title)
        })
    } else {
        uni.setNavigationBarTitle({
            title: typeList[options.type || 1] ? (typeList[options.type || 1].name as string) : ''
        })
    }

    language.value = options.lang || appStore.language.value.includes('zh') ? 'zh-cn' : 'en'
    const { ok, msg, data } = await getServiceProtocol(options.type || 1)
    if (ok) {
        content.value = data.content
    } else {
        uni.showToast({
            title: msg,
            icon: 'none'
        })
    }
})
</script>

<template>
    <view class="content">
        <mtHtml :content="$langFormat(content)"></mtHtml>
    </view>
    <!--  <view class="content" v-html="content"></view>-->
</template>

<style lang="scss" scoped>
.content {
    width: 100vw;
    overflow: hidden;
    padding: 15px 20px;
}
</style>
